Dreamweaver Article

Implementing User Authentication


Table of Contents

  1. Introduction
  2. Setting Up The Site
  3. User Authentication as a Web Application
  4. Introducing Sessions and Session Variables
  5. Implementing Registration
  6. Implementing Log-on
  7. Enabling Sessions With Application.cfm (ColdFusion Only)
  8. Restricting Access to Pages
  9. Implementing Log Out

Enabling Sessions With Application.cfm (ColdFusion Only)

One of the functions of the Log In User server behavior is that it creates a session variable when the user successfully logs in. The problem is, the session scope is inactive by default in ColdFusion, which means that the login page won't work. You'll have to activate session management in the ColdFusion Web Application Framework. Doing so is a simple matter of creating a new file (Application.cfm), and entering a single line of code.

  1. Create a new page in code view. Delete all of the code on the page, including any HTML, XML, or other tags or code.

    Application.cfm is not a regular web page, and so it should not have any code on it to begin.

  2. Type the following code:

    <cfapplication sessionmanagement="yes" setclientcookies="yes" name="user_auth"
    sessiontimeout="#CreateTimeSpan(0,0, 20, 0)#"> 
    

    Enabling Sessions with the Application.cfm file

    Figure 8. Enabling sessions with the Application.cfm file

    The cfapplication tag effectively creates an application and enables the web application framework. It has several attributes, many of which are optional. One required attribute is name, which is any name you want to give your application. The other attributes used enable session management, enable the setting of cookies, and create a session timeout.

    Note that rather than specifying a simple period of time in the sessiontimeout attribute, there is a function, CreateTimeSpan(). This function takes four parameters, standing for days, hours, minutes, and seconds. Thus, the sessiontimeout attribute is set for 20 minutes. In other words, if a user is inactive or leaves the site to browse on other pages for more than 20 minutes, all session variables associated with that user are flushed. In practical terms, it means the user would have to log in again.

  3. Save, close, and upload Application.cfm.

    At this point you can test the registration and login features you've added in this lesson. As mentioned earlier, try to break the application, by entering every variation you can think of.